home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / table / DefaultTableCellRenderer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  2.2 KB  |  68 lines

  1. package javax.swing.table;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.io.Serializable;
  6. import javax.swing.JComponent;
  7. import javax.swing.JLabel;
  8. import javax.swing.JTable;
  9. import javax.swing.UIManager;
  10. import javax.swing.border.Border;
  11. import javax.swing.border.EmptyBorder;
  12.  
  13. public class DefaultTableCellRenderer extends JLabel implements TableCellRenderer, Serializable {
  14.    protected static Border noFocusBorder;
  15.    private Color unselectedForeground;
  16.    private Color unselectedBackground;
  17.  
  18.    public DefaultTableCellRenderer() {
  19.       noFocusBorder = new EmptyBorder(1, 2, 1, 2);
  20.       ((JComponent)this).setOpaque(true);
  21.       ((JComponent)this).setBorder(noFocusBorder);
  22.    }
  23.  
  24.    public Component getTableCellRendererComponent(JTable var1, Object var2, boolean var3, boolean var4, int var5, int var6) {
  25.       if (var3) {
  26.          super.setForeground(var1.getSelectionForeground());
  27.          super.setBackground(var1.getSelectionBackground());
  28.       } else {
  29.          super.setForeground(this.unselectedForeground != null ? this.unselectedForeground : ((Component)var1).getForeground());
  30.          super.setBackground(this.unselectedBackground != null ? this.unselectedBackground : ((Component)var1).getBackground());
  31.       }
  32.  
  33.       ((JComponent)this).setFont(((Component)var1).getFont());
  34.       if (var4) {
  35.          ((JComponent)this).setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
  36.          if (var1.isCellEditable(var5, var6)) {
  37.             super.setForeground(UIManager.getColor("Table.focusCellForeground"));
  38.             super.setBackground(UIManager.getColor("Table.focusCellBackground"));
  39.          }
  40.       } else {
  41.          ((JComponent)this).setBorder(noFocusBorder);
  42.       }
  43.  
  44.       this.setValue(var2);
  45.       return this;
  46.    }
  47.  
  48.    public void setBackground(Color var1) {
  49.       super.setBackground(var1);
  50.       this.unselectedBackground = var1;
  51.    }
  52.  
  53.    public void setForeground(Color var1) {
  54.       super.setForeground(var1);
  55.       this.unselectedForeground = var1;
  56.    }
  57.  
  58.    protected void setValue(Object var1) {
  59.       ((JLabel)this).setText(var1 == null ? "" : var1.toString());
  60.    }
  61.  
  62.    public void updateUI() {
  63.       super.updateUI();
  64.       this.setForeground((Color)null);
  65.       this.setBackground((Color)null);
  66.    }
  67. }
  68.